package tst.testtask.services.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import tst.testtask.repositories.RequestRepository;
import tst.testtask.request.dto.ResultResponseDTO;
import tst.testtask.services.RequestService;

@Slf4j
@RequiredArgsConstructor
@Service
public class RequestServiceImpl implements RequestService {

    private final RequestRepository requestRepository;

    @Value("${param.sql.query:select * from ttable where id = ?}")
    private String query;

    @Override
    public ResultResponseDTO<Object> getRecordFromDB(Integer Id) {
        Map<String, Object> resultMap = requestRepository.findRecordQuery(query, Id);

        ResultResponseDTO<Object> result = ResultResponseDTO.builder()
        .data(resultMap)
        .response(true)
        .request(Id)
        .build();

        return result;
    }

}
